package com.bwie.task;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bwie.espojo.ESItem;
import com.bwie.mapper.ItemMapper;
import com.bwie.pojo.Item;
import io.micrometer.core.instrument.binder.BaseUnits;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.List;

/**
 * @description:
 * @author: ykk
 * @create: 2024-10-21 09:45
 **/
@Configuration
public class ESTask {


    @Autowired
    ElasticsearchRestTemplate elasticsearchRestTemplate;

    @Autowired
    ItemMapper itemMapper;


    @Scheduled(cron = "0 0/1 * * * ?")
    public void estask(){
        List<Item> list = itemMapper.selectList(new QueryWrapper<>());
        for (Item item : list) {
            ESItem esItem = new ESItem();
            BeanUtils.copyProperties(item,esItem);
            elasticsearchRestTemplate.save(esItem);
        }
    }
}
